#!/usr/bin/python
import re
import os
import settings

is_number = re.compile('\d+').match
def get_report():
    result = {}
    for name in os.listdir('/proc/'):
        if is_number(name):
            cmdline = open('/proc/%s/cmdline' % name).read()
            procname = cmdline.split('\x00')[0].split(' ')[0].rsplit('/')[-1]
            if procname:
                result.setdefault(procname, 0)
                result[procname] += 1
    for procname in list(result):
        if result[procname] < settings.PROCESSES_MIN_NUMBER:
            del result[procname]
    return result

if __name__ == '__main__':
    print get_report()
